package com.nhh.v.controller

import javax.validation.Valid

import com.google.common.collect.Maps
import com.nhh.v.anotation.ValidateHeader
import com.nhh.v.dto.RequiredRequestHeader
import com.nhh.v.service.{ResultData, ExchangeService}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation._
import reactor.core.publisher.Mono

/**
  * Created by chenkaiming on 2018/9/9.
  */

@RestController
@RequestMapping(path = Array("/api/exchange"))
@Validated
class ExchangeController(@Autowired val exchangeService: ExchangeService) {

  @PostMapping(path = Array("exchangeCoins"))
  def exchangeCoins(@Valid @ValidateHeader requireHeader: RequiredRequestHeader,
                    @RequestParam(value = "num", required = false, defaultValue = "0") num: String
                   ): Mono[_] = {
    Mono.just(exchangeService.exchangeCoins(requireHeader.getUid, num))
  }

  @PostMapping(path = Array("qrMyExchange"))
  def qrMyExchange(@Valid @ValidateHeader requireHeader: RequiredRequestHeader,
                   @RequestParam(value = "psize", required = false, defaultValue = "50") pSize: String,
                   @RequestParam(value = "pindex", required = false, defaultValue = "0") pIndex: String
                  ): Mono[_] = {

    Mono.just(exchangeService.qrMyExchange(requireHeader.getUid, pSize, pIndex))
  }
}

